package com.example.gaojt.androiddemo.statical.sdk;

import android.content.Context;

import com.example.gaojt.androiddemo.statical.DemoActivity;

import java.util.Map;

public class CommonParams {


    static class StaticParams {
        String mMAC;// TODO：mac地址
        String mAndroidID; // TODO：android id
        String mCUReference;// TODO：CU识别码 TCL手机专享
        String mAppsVersion;// TODO：应用当前版本
        public String mChannel;// TODO：渠道号
        public String mDeviceType;// TODO：设备类型（手机终端、平板、机顶盒）
        public String mDeviceName;// TODO：机型，设备名称，设备名称，比如ALCATEL OENETOUCH
        public String mSystemVersionCode;// TODO：系统版本号
        public String mSystemVersionName;// TODO：系统版本名
    }

    static StaticParams sObject;

    public String mIMEI1;// TODO：imei1
    public String mIMEI2;// TODO：imei2
    public String mUser;// TODO：存在帐号系统的用户账号
    public String mIMSI1;// TODO：imsi1
    public String mIMSI2;// TODO：imsi2
    public String mTime;// TODO：日志时间
    public String mNetwork;// TODO： 网络类型，比如wifi,移动网络
    public String mTimeZone;// TODO: 所在时区
    public String mCustomProjectName;// TODO:应用定制的项目名
    public String mLanguage;// TODO: 语言
    public String mRamSize;// TODO: ram大小
    public String mRomSize;// TODO: rom大小
    public String mAppPackageName;// TODO: 应用包名
    public String mScreenWH;// TODO: 屏幕分辨率大小
    public String mPhoneSize;// TODO:屏幕物理大小
    public String mIsRoot;// TODO: 是否root
    public String mMMC;// TODO:获取主卡的mmc
    private static final String DEFAULT_DEVICE_TYPE = "0";// 设备类型默认为0,代表手机

    private CommonParams() {}

    public static CommonParams getCommonParams(Context context, StatisticsApi.Config config) {
        initStaticParam(context, config);
        CommonParams commonParams = new CommonParams();
        commonParams.mIMEI1 = StatisticsUtils.getImei1(context);
        commonParams.mIMEI2 = StatisticsUtils.getImei2(context);
        commonParams.mUser = "";// TODO: 如果是有帐号系统，可以把用户信息上报
        commonParams.mIMSI1 = StatisticsUtils.getImsi1(context);
        commonParams.mIMSI2 = StatisticsUtils.getImsi2(context);
        commonParams.mTime = StatisticsUtils.getTime2GMT();
        commonParams.mNetwork = StatisticsUtils.getNetStatus(context);
        commonParams.mTimeZone = StatisticsUtils.getTimeZone();

        commonParams.mCustomProjectName = config.customProjectName;
        commonParams.mLanguage = StatisticsUtils.getLanguage();
        commonParams.mRamSize = StatisticsUtils.getRamSize();
        commonParams.mRomSize = StatisticsUtils.getRomSize();
        commonParams.mAppPackageName = context.getPackageName();
        commonParams.mScreenWH = StatisticsUtils.getScreenWH();
        commonParams.mPhoneSize = StatisticsUtils.getPhoneSize();
        commonParams.mIsRoot = StatisticsUtils.getIsRoot();
        commonParams.mMMC = StatisticsUtils.getMMC();
        return commonParams;
    }

    private static void initStaticParam(Context context, StatisticsApi.Config config) {

        if (sObject == null) {
            sObject = new StaticParams();
            sObject.mMAC = StatisticsUtils.getMacAddress();
            sObject.mAndroidID = StatisticsUtils.getAndroidId(context);
            sObject.mCUReference = StatisticsUtils.getCUReference();
            sObject.mAppsVersion = config.versionName;
            sObject.mChannel = config.channel;// TODO: BuildConfig.CHANNEL 渠道信息
            sObject.mDeviceType = DEFAULT_DEVICE_TYPE;
            sObject.mDeviceName = StatisticsUtils.getDeviceName();
            sObject.mSystemVersionCode = StatisticsUtils.getSystemVersionCode();
            sObject.mSystemVersionName = StatisticsUtils.getSystemVersionName();
        }
    }

    public static Map<String, String> convertCommonParam2Map(CommonParams commonParams) {
        Map<String, String> map = StatisticsUtils.getMap();
        map.put("IMEI1", commonParams.mIMEI1);
        map.put("IMEI2", commonParams.mIMEI2);
        map.put("MAC", sObject.mMAC);
        map.put("AID", sObject.mAndroidID);
        map.put("CU", sObject.mCUReference);
        map.put("TZ", commonParams.mTimeZone);
        map.put("USR", commonParams.mUser);
        map.put("IMSI1", commonParams.mIMSI1);
        map.put("IMSI2", commonParams.mIMSI2);
        map.put("APPV", sObject.mAppsVersion);
        map.put("CH", sObject.mChannel);
        map.put("T", commonParams.mTime);
        map.put("DT", sObject.mDeviceType);
        map.put("DN", sObject.mDeviceName);
        map.put("SVC", sObject.mSystemVersionCode);
        map.put("SVN", sObject.mSystemVersionName);
        map.put("NTW", commonParams.mNetwork);

        map.put("CPN", commonParams.mCustomProjectName);
        map.put("LG", commonParams.mLanguage);
        map.put("RAM", commonParams.mRamSize);
        map.put("ROM", commonParams.mRomSize);
        map.put("APN", commonParams.mAppPackageName);
        map.put("SWH", commonParams.mScreenWH);
        map.put("PZ", commonParams.mPhoneSize);
        map.put("IR", commonParams.mIsRoot);
        map.put("MMC", commonParams.mMMC);

        return map;
    }

}
